/*
 * Copyright 2014 Hieu Rocker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dev.dream.exochatlockscreen;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.rockerhieu.emojicon.Emojicon;
import com.rockerhieu.emojicon.EmojiconGridFragment;
import com.rockerhieu.emojicon.EmojiconsFragment;
import com.startapp.android.publish.StartAppSDK;

public class SendMessageActivity extends FragmentActivity implements
		EmojiconGridFragment.OnEmojiconClickedListener,
		EmojiconsFragment.OnEmojiconBackspaceClickedListener {
	EditText mEditEmojicon;
	Button sendMsg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.send_message_exo);

		StartAppSDK.init(this, "111076217", "210808285", true);

		mEditEmojicon = (EditText) findViewById(R.id.editEmojicon);

		mEditEmojicon.addTextChangedListener(new TextWatcherAdapter() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

				if (s.length() == 100) {
					Toast.makeText(getApplicationContext(),
							"Max length of Message", 1000).show();
				}
			}
		});

		sendMsg = (Button) findViewById(R.id.btnSendMsg);
		sendMsg.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				EXOChatKeypadPreferences.getInstance().initPreferences(
						getApplicationContext());
				if (!mEditEmojicon.getText().toString().equals("")) {
					EXOChatKeypadPreferences.getInstance().setTextSendMsg(
							mEditEmojicon.getText().toString());
				} else {
					EXOChatKeypadPreferences.getInstance().setTextSendMsg(
							EXOChatKeypadPreferences.DEFAULT_TEXT_SEND_MSG);
				}
				Toast.makeText(getApplicationContext(), "Send message success",
						1000).show();
				finish();
			}
		});
	}

	@Override
	public void onEmojiconClicked(Emojicon emojicon) {
		EmojiconsFragment.input(mEditEmojicon, emojicon);

	}

	@Override
	public void onEmojiconBackspaceClicked(View v) {
		EmojiconsFragment.backspace(mEditEmojicon);
	}
}
